package com.zhoukun.cloud.controller;


import com.zhoukun.cloud.CommentRest;
import com.zhoukun.cloud.service.FeignService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


import java.math.BigDecimal;

/**
 * @author zhoukun 86547462@qq.com
 * @version 1.0
 * @date 2020/10/24 21:06
 */
@RestController
@RefreshScope //自动刷新只能刷新 @RefreshScope 注解下的配置，一些特殊配置，如数据库等，需要同样先设置数据库链接ConfigServer类，然后通过加 @RefreshScope 注解方式
@Log4j2
public class PaymentController {



    @Autowired
    FeignService service;
    //查询
    @GetMapping("/con/query")
    public CommentRest query()
    {
        return service.query();
    }


    //查询单个
    @GetMapping("/con/queryById/{Id}")
    public CommentRest queryById(@PathVariable String Id)
    {
        return service.queryById(Id);
    }

    //修改余额
    @GetMapping("/con/banUP/{Id}/{money}")
    public CommentRest banUP(@PathVariable String Id,
                             @PathVariable BigDecimal money)
    {

        return service.banUP(Id,money);
    }

    //ribbon的超时时间测试
    @GetMapping("/con/outTime")
    public CommentRest outTime() throws InterruptedException {


        return service.outTime();
    }

    //服务降级测试
    @GetMapping("/con/demotion/{num}")
    public CommentRest demotion(@PathVariable int num)
    {
        return service.demotion(num);
    }
    //服务熔断测试
    //服务熔断测试
    @GetMapping("/con/fusing/{num}")
    public CommentRest fusing(@PathVariable int num) throws Exception {
         return service.fusing(num);
    }


    //查看当前环境
    @Value("${info.environment}")
    String environment;
    @GetMapping("/con/environment")
    public String environment(){
        return environment;
    }
}
